package com.cwm.test.composite.demo.transparent;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CoursePage extends CourseComponent {

    private String name;
    private Integer level;
    private List<CourseComponent> items = new CopyOnWriteArrayList<>();


    public CoursePage(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public boolean addChild(CourseComponent component) {
        items.add(component);
        return true;
    }

    @Override
    public String getName() {
        return this.name;
    }


    @Override
    public void print() {

        System.out.println(name);

        for (CourseComponent cc : items) {
            if (this.level != null) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print("  ");
                }
                for (int i = 0; i < this.level; i++) {
                    if (i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("-");
                }
            }
            cc.print();
        }
    }

}
